package com.compass.doctor.dialog

import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.compass.doctor.databinding.DialogChooseBankCardBinding
import com.compass.doctor.ui.mine.AddBankCardActivity
import com.compass.doctor.ui.mine.adapter.DialogBankCardAdapter
import com.compass.framework.base.BaseDialog
import com.compass.framework.base.BaseDialogFragment
import com.compass.framework.ext.onClick
import com.compass.framework.model.WithdrawType

/**
 * Description： 选择银行卡dialog
 * Date:2023/12/26 21:40
 */
class ChooseBankCardDialog {
    class Builder(activity: FragmentActivity,private var withdrawType :MutableList<WithdrawType>) : BaseDialogFragment.Builder<Builder>(activity) {

        private val mBinding: DialogChooseBankCardBinding =
            DialogChooseBankCardBinding.inflate(LayoutInflater.from(activity))
        private lateinit var dialogBankCardAdapter: DialogBankCardAdapter

        init {
            initView()
        }

        private fun initView() {
            dialogBankCardAdapter=DialogBankCardAdapter()
            setContentView(mBinding.root)
            setWidth(ViewGroup.LayoutParams.MATCH_PARENT)
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
            setAnimStyle(BaseDialog.AnimStyle.BOTTOM)
            gravity = Gravity.BOTTOM
            mBinding.tvCancel.onClick {
                dismiss()
            }
            mBinding.tvAddCard.onClick {
                AddBankCardActivity.start(context)
                dismiss()
            }

            mBinding.rcyCard.apply {
                layoutManager = LinearLayoutManager(activity)
                adapter = dialogBankCardAdapter
            }
            dialogBankCardAdapter.onItemClickListener = { _:View,p:Int->
                val item = withdrawType.get(p)
                item.let {
                   if("1" == item.type){
                       //银行卡
                   }else if("2" == item.type){
                       //微信
                       if(!item.bindStatus){
                           //没有绑定微信，先去调起微信授权，进行微信微信绑定
                           bindWxAccount()
                       }else{
                           //已经绑定微信了，直接将微信信息填写在页面中
                       }
                   }
                }

            }
            dialogBankCardAdapter.setData(withdrawType)
        }

        /**
         * 调起微信进行绑定
         */
        private fun bindWxAccount(){

        }

    }
}